package com.agile.leetcode.easy.nextGreaterElement;


import java.util.Arrays;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/8 11:08
 */
public class NextGreaterElement {
    public static void main(String[] args) {
        NextGreaterElement nextGreaterElement=new NextGreaterElement();
        int[] nums1={2,4};
        int[] nums2={1,2,3,4};
        int[] ints = nextGreaterElement.nextGreaterElement(nums1, nums2);
        System.out.println(Arrays.toString(ints));
    }
    public int[] nextGreaterElement(int[] nums1,int[] nums2){
        // 创建数组
        int[] result=new int[nums1.length];
        // 遍历子数组
        for (int i = 0; i < nums1.length; i++) {
            // 遍历
            boolean flag=true;
            // 定义临时变量
            int temp=-1;
            for (int j = 0; j < nums2.length; j++) {
                if (flag){
                    if (nums1[i]!=nums2[j]) {
                        continue;
                    }else {
                        flag=false;
                        continue;
                    }
                }
                if (nums2[j]>nums1[i]){
                    temp=nums2[j];
                    break;
                }
            }
            result[i]=temp;
        }
        return result;
    }
}
